<template>
  <el-form :model="detailForm" ref="detailForm" :inline="false"
           :label-position="labelPosition" :class="isEdit?'':'formItem'">
    <!--备注-->
    <el-card class="box-card" shadow="never">
      <div slot="header" class="header-card">
        <span class="header-card-title">备注</span>
      </div>
      <el-row :gutter="24">
        <el-col>
          <el-form-item label="上传附件:" prop="attachmentUrl"
                        :rules="{required:state=== 'write',message:'请上传附件',trigger: 'blur'}">
            <image-common v-model="detailForm.attachmentUrl" :limit="1" :disabled="!isEdit" :upType="2"/>
          </el-form-item>
        </el-col>

      </el-row>
      <el-row :gutter="24">
        <el-col v-if="isShow">
          <el-form-item label="附言说明:" prop="description">
            <el-input v-if="isEdit" type="textarea" v-model="detailForm.description" placeholder="请输入附言说明"
                      :rows="4"></el-input>
            <span v-else>{{ detailForm.description }}</span>
          </el-form-item>
        </el-col>
      </el-row>

    </el-card>

  </el-form>
</template>

<script>
export default {

  name: 'remark',//备注


  props: {
    value: {
      type: Object,
      default: {}
    },
    state: {
      type: String,
      default: "",
    },
  },

  computed: {
    detailForm: {
      get() {
        let that = this
        const proxy = new Proxy(that.value, {
          get(target, key) {
            return Reflect.get(target, key)
          },
          set(target, key, value) {
            if (value) {
              that.handleClear(key)
            }
            that.$emit('input', {...target, [key]: value})
            return true
          }
        })
        return proxy
      }
    },
    labelPosition() {
      if (this.state === 'write') {
        return "top";
      } else {
        return "right";
      }
    },
    isEdit() {
      let bool;
      switch (this.state) {
        case "write":
          bool = true;
          break;
        case "disabled":
          bool = false;
          break;
        case "readonly":
          bool = false;
          break;
      }
      return bool;
    },
  },


  watch: {},
  data() {
    return {
      isShow: true,
      obj: {},
      shopInsuranceBool: false,//店保
      ourCompanyBool: false,//我司
      activityName: '',
      formId: '',
      bool: false,
    }
  },
  created() {

  },

  methods: {

    handleEffect() {
      return new Promise((resolve, reject) => {
        this.$refs.detailForm.validate((valid) => {
          if (valid) {
            resolve();
          } else {
            this.locateToErr()
            reject();
          }
        });
      })
    },

    locateToErr() {

      this.$nextTick(() => {
        let isError = document.getElementsByClassName('is-error')
        isError[0].scrollIntoView({
          // 滚动到指定节点
          // 值有start,center,end，nearest，当前显示在视图区域中间
          block: 'center',
          // 值有auto、instant,smooth，缓动动画（当前是慢速的）
          behavior: 'smooth',
        })
      })
    },
    handleClear(str) {
      this.$refs.detailForm.clearValidate(str);
    },

    valid() {
      return new Promise((resolve, reject) => {
        this.$refs.detailForm.validate((valid) => {
          resolve(valid);
        });
      })
    },

  }
}
</script>

<style lang="scss" scoped>
@import "@/styles/cwgd/formScss.scss";
</style>
